<template>
  <div id="app">
       <HeaderNav 
        v-if="ifshowMeum"
        :title="'我的网站'"
        :menu-items="navMenu"
        :user="currentUser"
        @menu-click="handleMenuClick"
        @login="handleLogin"
      />
      <router-view></router-view>
      <BottomNav 
         v-if="ifshowMeum"
        :nav-items="bottomNavItems"
        @nav-click="handleNavClick"
      />
  </div>
</template>

<script>
import HeaderNav from './components/topnav.vue'
import BottomNav from './components/bottomnav.vue'
import request from './untils/request'
export default {
  name: 'App',
  components: { HeaderNav, BottomNav },
  data() {
    return {
      navMenu: [], // 头部导航
      currentUser: {
        name: '张三',
        avatar: 'path/to/avatar.jpg'
      },
       bottomNavItems: [], // 底部导航
      ifshowMeum: true
    }
  },
  created(){
    const path = window.location.href
    if(path.indexOf('login') > 0){
      this.ifshowMeum = false
    } else {
      this.getnavMenu()
      this.getbottomNavItems()
    }
  },
  methods: {
    getbottomNavItems(){
       let params = {
        position: 0
       }
       request.get('/home/nav', params).then(res => {
          this.bottomNavItems = res.result
      })
    },
    getnavMenu(){
       let params = {
        position: 1
       }
       request.get('/home/nav', params).then(res => {
            this.navMenu = res.result
      })
    },
    handleMenuClick(item) {
      console.log('点击菜单:', item.text)
    },
    handleLogin() {
      console.log('点击登录按钮')
    },
    // 底部导航
     handleNavClick(item) {
      console.log('点击底部导航:', item.text)
    }
  }
}
</script>

<style>
body{
  margin: 0;
  padding: 0;
}

</style>
